/*
 create by sys on 2016/11/22.
 */

define(["require",'config/appregister',"business/Companyinfor/service/htttp","business/services/filter","jquery","business/workSkill/directive/startLevel"],function(require,app,httpServices){
    app.controller('resourceCtrl',function($scope,$timeout,$state,auth){
        auth.isCompanyLogin();
        /*资源管理*/
        $scope.noContent = '您还没有发布博文';
        $scope.noContent2="您还没有发布课程，赶快去发布吧！";
        $scope.noContent3 = "您还没有上传视频，赶快去上传吧！"
     	$scope.sgiw=function(){
     		alert("未通过审核无法查看详情哦")
     	}
        /*默认显示1的课程列表*/
        $scope.listParamsss = {
            currentTcId: "",
            download: false,
            time: false,
            pageNo: 1,
            pageSize:10,
            all: false,
            typeId: "",
            scId: "",
            dcId: "",
            keyWord:"",
            //dcName scName 用于加入缓存 在详情中显示面包树导航
            dcName:"",
            scName:""
        };
      $scope.listParam2s = {
            currentTcId: "",
            download: false,
            time: false,
            pageNo: 1,
            pageSize:10,
            all: false,
            typeId: "",
            scId: "",
            dcId: "",
            keyWord:"",
            //dcName scName 用于加入缓存 在详情中显示面包树导航
            dcName:"",
            scName:""
        };
           $scope.listParamsCons = {
            currentTcId: "",
            download: false,
            time: false,
            pageNo: 1,
            pageSize:10,
            all: false,
            typeId: "",
            scId: "",
            dcId: "",
            keyWord:"",
            //dcName scName 用于加入缓存 在详情中显示面包树导航
            dcName:"",
            scName:""
        };
        //企业信息
        function companyInfo(){
            var req ={
                type:"GET",
                uri:"getBaseInfoByUser",
                data:{}
            };
            httpServices.homePageHttpService(req).success(function(result){
                $scope.$apply(function(){
                    $scope.compayId = result.data.companyId;
                    courseList2();
                    getweifenlei();
                })
            });
        }
        companyInfo();
        function courseList2(){
            var req ={
                type:"GET",
                uri:"getList",
                data:{
                    companyId:$scope.compayId,
                    pageNo:$scope.listParamsss.pageNo,
                    pageSize:$scope.listParamsss.pageSize,
                }
            };
            httpServices.getcourse(req).success(function(response){
                $scope.$apply(function(){
                    $scope.courseList = response.data.list;
                    $scope.startLevel = response.data.list.collectionCount;
                    $scope.total=$scope.totalItem = response.data.Pagination.totalCount;
                    getListModel2();
                })
            });
        }
        
          /*大列表跳转页面*/
        $scope.list = [];
        function getListModel2(){
            $scope.paginationConf = {
                currentPage: $scope.listParamsss.pageNo,
                totalItems: $scope.totalItem,
                //每页预览条数
                itemsPerPage:$scope.listParamsss.pageSize,
                //分页总数
                numberOfPages:Math.ceil($scope.totalItem/$scope.listParamsss.pageSize),
                // 实际分页长度
                pagesLength:5,
                perPageOptions: [10, 20, 30, 40, 50],
                onChange: function (currentPage) {
                    if(currentPage){
                        $scope.paginationConf.currentPage = currentPage;
                    }
                    $scope.list = [];
                    $scope.listParamsss.pageNo = $scope.paginationConf.currentPage;
                    courseList2();
                }
            };
        }
        function getweifenlei(){
        	var req ={
                type:"GET",
                uri:"getList",
                data:{
                    type:0,
                    companyId:$scope.compayId,
                    pageNo:$scope.listParams.pageNo,
                    pageSize:$scope.listParams.pageSize,
                    all:"false"
                }
            };
            httpServices.getcourse(req).success(function(response){
                $scope.$apply(function(){
                    console.log(response)
					$scope.courseList = response.data.list;
                    $scope.startLevel = response.data.list.collectionCount;
                    $scope.total2=$scope.totalItem = response.data.Pagination.totalCount;
      
                })
            });
        }

        $scope.showAll2s=function(){
        	$scope.fcolor=-2;
        	 getweifenlei(); 
        }
        
        $scope.showAll=function(){
             courseList2();
             $scope.fcolor=-1;
        }
        $scope.fcolor=-1;
        $scope.showItmCOn=function(item,index){
        	$scope.fcolor=index;
             gettypecourse(item);
            
        }
        function gettypecourse(item){
        		var req ={
                type:"GET",
                uri:"getList",
                data:{
                    companyId:$scope.compayId,
                    type:item.id,
                    pageNo:$scope.listParamsss.pageNo,
                    pageSize:$scope.listParamsss.pageSize,
                    all:"false",
                }
            };
            httpServices.getcourse(req).success(function(response){
                $scope.$apply(function(){
					$scope.courseList = response.data.list;
                    $scope.startLevel = response.data.list.collectionCount;
                   $scope.totalItem=response.data.Pagination.totalCount;
					getListModel2sss();
                })
            });
        	}
      	$scope.list = [];
        function getListModel2sss(){
            $scope.paginationConf = {
                currentPage: $scope.listParamsss.pageNo,
                totalItems: $scope.totalItem,
                //每页预览条数
                itemsPerPage:$scope.listParamsss.pageSize,
                //分页总数
                numberOfPages:Math.ceil($scope.totalItem/$scope.listParamsss.pageSize),
                // 实际分页长度
                pagesLength:5,
                perPageOptions: [10, 20, 30, 40, 50],
                onChange: function (currentPage) {
                    if(currentPage){
                        $scope.paginationConf.currentPage = currentPage;
                    }
                    $scope.list = [];
                    $scope.listParamsss.pageNo = $scope.paginationConf.currentPage;
                    gettypecourse();
                }
            };
        }
        /*热门课程点击调转*/
        /*动态添加删除文件夹*/
        $scope.creatCons=[];
        $scope.add=function(a){
            var obj = {
                id:0,
                name:a
            }///obj发送给后台即可文件夹分类
            $scope.creatCons.push(obj);
        }
        $scope.del=function(item,idx){
            $scope.creatCons.splice(idx,1);
            var req ={
                type:"DELETE",
                uri:"deleteCourseType",
                data:{
                    typeId:item.id
                }
            };
            httpServices.postcoursetype(req).success(function(response){
                $scope.$apply(function(){
                })
            });
        }
        $scope.addcLass = function(item,index){
            item.isHover = !item.isHover;
        }
        /*获取课程分类*/
        $scope.getTypeName = function(item){
            var courseType = "未分类";
            if(item == 0){
            	  courseType = "未分类";
            	  return courseType;
            }else{
            	for(var i = 0;i < $scope.creatCons.length;i++){
	                if(item == $scope.creatCons[i].id){
	                    courseType = $scope.creatCons[i].name;
	                }
            	}
            	 return courseType;
            }   
        }

        function getcouser(){
            var req ={
                type:"GET",
                uri:"getCourseType",
                data:{}
            };
            httpServices.postcoursetype(req).success(function(response){
                $scope.$apply(function(){
                    $scope.creatCons=response.data;
                })
            });
        }
        getcouser();
        $scope.showpropmt=function(){
            $scope.showpropmts=1;
            getcouser();
        }
        //发送课程分类数据到后台
        $scope.saveCourseType=function(){
            var str =JSON.stringify($scope.creatCons);
            var req ={
                type:"POST",
                uri:"updateCourseType",
                data:{
                    jsonStr:str
                }
            };
            httpServices.postcoursetype(req).success(function(response){
                $scope.$apply(function(){
                    $scope.showpropmts=2;
                })
            });
        }
            $scope.tab=4;
         
		$scope.singVideo=function(item){

			$state.go("eng.vedioDetails",{courseId:item.courseId,hidePlay:1})
		}
        $scope.singVideoplay=function(item){
  
           /* $state.go("eng.videoPlay",{videoPlayId:item.videoId})*/
            window.open('http://www.gongchengjie.cn/#/eng/videoPlay?videoPlayId='+item.videoId)
        }
		$scope.modeVIdeo=function(item){
            $state.go("VideomodifyCtrl",{courseId:item.courseId})
        }
        $scope.modeVIdeo2=function(item){
            $state.go("videoUploadCtrl",{moveVideoId:item.videoId})
        }
        $scope.showClassCon=function(index){
            $($(".clsaaCon")[index]).show()
            $($(".courseClass")[index+1]).hide();
            $($(".courseClass")[index]).css("z-index",8)
           	$(".videoTit").css("z-index",1)
        }
        $scope.hideClassCon=function(index){
            $($(".clsaaCon")[index]).hide()
            $($(".courseClass")[index+1]).show();
            $($(".courseClass")[index]).css("z-index",1)
             $(".videoTit").css("z-index",8)
        }
        $scope.modeCourseClass2=function(item){
        	 $scope.hidws=1;
        	 console.log($scope.getTypeName)
            var req ={
                type:"POST",
                uri:"updateType",
                data:{
                    courseId:item.courseId,
                    typeId:0
                }
            };
            httpServices.getcourse(req).success(function(response){
                $scope.$apply(function(){
                   
                })
            });
        	
        }
        $scope.modeCourseClass=function(item,item2){
        	 $scope.hidws=2;
            $scope.getTypeName(item2.id)
            var req ={
                type:"POST",
                uri:"updateType",
                data:{
                    courseId:item.courseId,
                    typeId:item2.id
                }
            };
            httpServices.getcourse(req).success(function(response){
                $scope.$apply(function(){
                    courseList2();
                    $scope.fcolor=-1;
                })
            });

        }
        $scope.ResourceTab=2
      		 if(sessionStorage.ResourceTab==3){
      		 	   $scope.ResourceTab=3;
            		getvideolist();
            	  
            }else if(sessionStorage.ResourceTab==2){
            	$scope.ResourceTab=sessionStorage.ResourceTab;   
            }else{
            	            getCompnayBlog();
            }
        $scope.ResourceTabCOnOne=function(){
            $scope.ResourceTab=1;
            courseList2()
            sessionStorage.removeItem("ResourceTab")
        }
        $scope.ResourceTabCOnthr=function(){
            $scope.ResourceTab=3;
            getvideolist();
        }

        function getvideolist(){
        	 sessionStorage.removeItem("ResourceTab")
            var req ={
                type:"GET",
                uri:"getList",
                data:{
                    type:1,
                    pageNo: $scope.listParam2s.pageNo,
                    pageSize:$scope.listParam2s.pageSize,
                    all:"false"
                }
            };
            httpServices.getSameVideo(req).success(function(response){
                $scope.$apply(function(){
                    $scope.videolist = response.list;
                    $scope.totalItems=response.Pagination.totalCount;
                    getListModelcon();
                })
            });
        }
        $scope.list = [];
        function getListModelcon(){
            $scope.paginationConf = {
                currentPage: $scope.listParam2s.pageNo,
                totalItems: $scope.totalItems,
                //每页预览条数
                itemsPerPage:$scope.listParam2s.pageSize,
                //分页总数
                numberOfPages:Math.ceil($scope.totalItems/$scope.listParam2s.pageSize),
                // 实际分页长度
                pagesLength:5,
                perPageOptions: [10, 20, 30, 40, 50],
                onChange: function (currentPage) {
                    if(currentPage){
                        $scope.paginationConf.currentPage = currentPage;
                    }
                    $scope.list = [];
                    $scope.listParam2s.pageNo = $scope.paginationConf.currentPage;
                    getvideolist();
                }
            };
        }
        
     
        
        $scope.ResourceTabCOn=function(){
            $scope.ResourceTab=2;
            sessionStorage.removeItem("ResourceTab")
        	 getCompnayBlog(1,10);
          
        }
        
       
           function getCompnayBlog(a,b){
                var req ={
                    type:"GET",
                    uri:"getList",
                    data:{
                        type:1,
                        pageNo: $scope.listParamsCons.pageNo,
                        pageSize:$scope.listParamsCons.pageSize,
                        all:"false"
                    }
                };
                httpServices.getBlog(req).success(function(response){
                    $scope.$apply(function(){
                        $scope.CompanyBlogCon= response.data.list;
                        $scope.totalItem=response.data.Pagination.totalCount;
                        getListModelbog();
                    })
                });
            }

            $scope.list = [];
            function getListModelbog(){
                $scope.paginationConf = {
                    currentPage: $scope.listParamsCons.pageNo,
                    totalItems: $scope.totalItem,
                    //每页预览条数
                    itemsPerPage:$scope.listParamsCons.pageSize,
                    //分页总数
                    numberOfPages:Math.ceil($scope.totalItem/$scope.listParamsCons.pageSize),
                    // 实际分页长度
                    pagesLength:5,
                    perPageOptions: [10, 20, 30, 40, 50],
                    onChange: function (currentPage) {
                        if(currentPage){
                            $scope.paginationConf.currentPage = currentPage;
                        }
                        $scope.list = [];
                        $scope.listParamsCons.pageNo = $scope.paginationConf.currentPage;
                        getCompnayBlog($scope.listParamsCons.pageNo,10);
                    }
                };
            }
          function getPeopleblog(){
                var req ={
                    type:"GET",
                    uri:"getGreetBlog",
                    data:{
                        count:8
                    }
                };
                httpServices.getBlog(req).success(function(response){
                    $scope.$apply(function(){
                        $scope.PeoPleCon =response.data;
                    })
                });
            }
            getPeopleblog();
        
        
        /*博文详情*/
        $scope.showDeatilscon=function(blogId){
           $state.go("comIndexCtrl.comPanyBlogCtrl",{comPanyBlogId:blogId})
        }
        $scope.showDeatilsconperson=function(blogId,userId){
        	
           $state.go("othersBlogInfo",{userId:userId,blogId:blogId})
        }
        $scope.showDeatilsconCompany=function(blogId,userId){
        	$state.go("outIndexCtrl.bwDetailCtrl",{outBlogId:blogId,companyId:userId})
        }
        $scope.modeBlog=function(blogId){
        	$state.go("blogmod",{blogid:blogId,blogType:1})
        }
		$scope.DeleteCompanyBlgo=function(blogId){
			var msg = "您真的确定要删除吗？删除后将从列表中消失\n\n请确认！";
			if (confirm(msg)==true){
				var req ={
                    type:"GET",
                    uri:"del",
                    data:{
                       blogid:blogId
                    }
                };
                httpServices.getBlog(req).success(function(response){
                    $scope.$apply(function(){
                    	var req ={
		                    type:"GET",
		                    uri:"getList",
		                    data:{
		                        type:1,
		                        pageNo: $scope.listParams.pageNo,
		                        pageSize:$scope.listParams.pageSize,
		                        all:"false"
		                    }
		                };
		                httpServices.getBlog(req).success(function(response){
		                    $scope.$apply(function(){
		                   
		                        $scope.CompanyBlogCon= response.data.list;
		                       
		                    })
		                });
                    })
                });
			}else{
				return false;
			}
			
		}
    	$scope.sendCOmpanyBlog=function(){
    		/*$state.go("blogpost",{blogType:1})*/
    		window.open("http://www.gongchengjie.cn/#/blogpost?blogType=1")
    	}
    	$scope.sendCOmpanyVideo=function(){
    		$state.go("commpanyVideoCtrl")
    	}
        $scope.sendCOmpanyVideo2=function(){
            $state.go("videoUploadCtrl")
        }
    })
});
